#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/workqueue.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("chuan@xaut.edu.cn");
MODULE_DESCRIPTION("This is a test module progamm");
static struct workqueue_struct * queue = NULL;
static struct delayed_work dwork; //here, use struct delayed_work instead of work_struct
void work_handle(struct work_struct * work)
{
printk(KERN_ALERT "after 5 seconds, xaut's work running....\n");
}
static int init_workqueue(void)
{
queue = create_workqueue("xaut_queue_events");
printk(KERN_ALERT "workqueue.mod loading....ok\n");
if(queue == NULL)
{
printk(KERN_ALERT "create xaut's workqueue error\n");
return -1;
}
INIT_DELAYED_WORK(&dwork, work_handle); //here, use INIT_DELAYED_WORK
printk(KERN_ALERT "work_handle init....ok\n");
queue_delayed_work(queue, &dwork, 5000); //here, the 2nd parameter is delayed_work type.
return 0;
}
static void exit_workqueue(void)
{
flush_workqueue(queue);
cancel_delayed_work(&dwork);
destroy_workqueue(queue);
printk(KERN_ALERT "xaut's workqueue unloading....ok\n");
}
module_init(init_workqueue);
module_exit(exit_workqueue);
